#include<iostream>
#include<unordered_map>
const int N = 1e6 + 10;
typedef long long ll;
using namespace std;
ll num[N];
int main()
{
	unordered_map <int, int> mp;
	ll n, m;cin >> n >> m;
	for (int i = 1; i <= n; i++)
	{
		cin >> num[i];
		mp[num[i]]++;
	}
	ll count2 = 0;
	for (int i = 1; i <= n; i++)
	{
		ll u = num[i] + m;
		count2 += mp[u];
	}
	cout << count2 << endl;
	return 0;
}
//#include<iostream>
//#include<set>
//using namespace std;
//const int N = 1e6 + 10;
//int num[N];
//int main()
//{
//	multiset <int> mp;
//	int n, m;cin >> n >> m;
//	for (int i = 1; i <= n; i++)
//	{
//		int x;cin >> num[i];
//		mp.insert(num[i]);
//	}
//	int count2 = 0;
//	for (auto v : mp)
//	{
//		int u = v + m;
//		count2 += mp.count(u);
//	}
//	cout << count2 << endl;
//	return 0;
//}
////#include<iostream>
////#include<set>
////using namespace std;
////const int N = 1e6 + 10;
////int INF = N;
////int num[N];
////int main()
////{
////	multiset<int> mp;mp.insert(N);mp.insert(-N);
////	int count2 = 0,n, m;cin >> n >> m;
////	for(int i = 1;  i <= n; i++)
////	{
////		int x;cin >> num[i];
////		mp.insert(x);
////	}
////	for (int i = 1;i <= n; i++)
////	{
////		auto t = mp.lower_bound(num[i]);
////		auto tmp = t;
////		tmp--;
////		while (*tmp != INF)
////		{
////			if (num[i] - *tmp == m) count2++;
////			tmp--;
////		}
////	}
////	cout << count2 << endl;
////	return 0;
////}
//////#inc
////// lude<iostream>
//////#include<set>
//////const int N = 1e6 + 10;
//////int num[N];
//////using namespace std;
//////int main()
//////{
//////	multiset<int> mp;int count2 = 0;
//////	int n, m;scanf("%d%d",&n,&m);
//////	for (int i = 1; i <= n; i++)
//////	{
//////		scanf("%d", &num[i]);
//////		mp.insert(num[i]);
//////	}
//////	for (int i = 1; i <= n; i++)
//////	{
//////		int cha = num[i] - m;
//////		int k = mp.count(cha);
//////		if (k) count2 += k;
//////	}
//////	printf("%d\n", count2);
//////	return 0;
//////}